package S05;

public class N04 {
	//9.1.5 通过函数返回值引用子类对象
	public static Person getInstance(String type) {
		if(type.equals("Person")) {
			return new Person("张三", 20);
		}else if(type.equals("Student")) {
			return new Student("李四", 19, "水环学院");
		} else if(type.equals("Monitor")) {
			return new Monitor("王五", 21, "水环学院");
		}
		return null;
	}
	public static void main(String[] args) {
		System.out.println(getInstance("Person").whoami());
		System.out.println(getInstance("Student").whoami());
		System.out.println(getInstance("Monitor").whoami());
	}
}
